<template>
    <div>
        <el-table :data="store.getters['banner/getBanner']" border style="width: 100%">
            <el-table-column prop="id" label="编号" width="180" />
            <el-table-column prop="title" label="轮播图标题" />
            <el-table-column prop="address" label="图片">
                <template v-slot="item">
                    <div>
                        <img :src="item.row.img" alt="" class="img" v-if="item.row.img">
                    </div>
                </template>
            </el-table-column>
            <el-table-column prop="address" label="状态" width="80">
                <template v-slot="item">
                    <div>
                        <el-tag v-if="item.row.status == 1" type="success" plain size="default">启用</el-tag>
                        <el-tag v-else type="danger" plain size="default">禁用</el-tag>
                    </div>
                </template>
            </el-table-column>
            <el-table-column prop="address" label="操作">
                <template v-slot="item">
                    <div>
                        <el-button type="primary" size="small" @click="edit(item.row.id)">编辑</el-button>
                        <el-button type="danger" size="small" @click="del(item.row.id)">删除</el-button>
                    </div>
                </template>
            </el-table-column>

        </el-table>
    </div>
</template>
<script lang="ts" setup>
import { useStore } from 'vuex';
import { bannerdelete } from '@/request/api';
import { ElMessage, ElMessageBox } from 'element-plus'
import { defineEmits } from 'vue';
let emit = defineEmits(['edit'])
let store = useStore()
let edit = (id:number) =>{
   emit("edit",id)
}
let del = (id:number) =>{
    ElMessageBox.confirm(
    '删除后不可恢复，是否确认删除？',
    {
      confirmButtonText: '删除',
      cancelButtonText: '取消',
      type: 'warning',
    }
  )
    .then(() => {
        bannerdelete({ id }).then(res => {
        if (res.code == 200) {
          get()
          ElMessage({
            type: 'success',
            message: '删除成功！',
          })
        }
      })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: '取消删除！',
      })
    })


}
let get = () =>{
    store.dispatch("banner/getBannerListAction")
}
get()

</script>
<style>
.img {
    width: 100px;
    height: 100px;
}
</style>